/*******************************************************************************
 ** Name: main.cpp                                                             **
 ** Description:              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2010  Barry Gian James. <bjames@unix-arm.org>          **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL$
 ******************************************************************************/
// Portions (C) 2011 OpenHouseware, LLC.
// All Rights Reserved

#define _MUNIX_ATBIOSMAIN_H_ "$Id$"
// Last Modified $DateTime: 2010/02/12 01:42:30 $ by $Author$

#include <avr/io.h>
//#include <util/delay.h>
#include <stdio.h>
#include "common.h"
#include "atbios.h"
#include "progmem.h"
#include "mtime.h"

#define BIOS_VERSION_MAJ    0
#define BIOS_VERSION_MIN    3
#define BIOS_ARCH           "ATmega644P"
#define BIOS_INSTRUCTION    "avr5"

// prototypes
void    BIOSPortTest(void);

extern int sprintf_P(char *__s, const char *__fmt, ...);

// The one and only ATBIOS
ATBIOS      bios;
static char gBuff[80];

int main()
{
    if (bios.Init() == false) {
        bios.Debug(failed,true);
        asm("rjmp 0");
    }

    BIOSPortTest();

    if (!bios.InitIO())
        bios.Debug(failed,true);
    if (!bios.InitMem())
        bios.Debug(failed,true);
    if (!bios.InitKernel())
        bios.Debug(failed,true);

    for (;;)
    {

    }

    return (-1);
}

// TODO
ISR(USART0_RX_vect)
{

}

void BIOSPortTest()
{
    sprintf_P(gBuff,preCnct,(bios.dbg()).Baud());
    bios.Debug(gBuff);
    bios.Debug(pmPOST1,true);
    bios.Debug(greetz,true);
    bios.Debug(pmBIOSPortTest,true);

    sprintf_P(gBuff,fwVersion,BIOS_VERSION_MAJ,BIOS_VERSION_MIN);
    bios.Debug(gBuff);
    sprintf_P(gBuff,hwVersion,BIOS_ARCH,(F_CPU/1000000),BIOS_INSTRUCTION);
    bios.Debug(gBuff);
    bios.Debug(pmBIOSProxy,true);
    sprintf_P(gBuff,pmBIOSProxy1,&bios.cfg(),PORTB, 0);
    bios.Debug(gBuff);
    sprintf_P(gBuff,pmBIOSProxy2,bios.cfg().ID());
    bios.Debug(gBuff);
    sprintf_P(gBuff,pmBIOSProxy3,bios.cfg().ID()); // TODO
    bios.Debug(gBuff);
    sprintf_P(gBuff,pmBIOSProxy4,bios.cfg().ID()); // TODO
    bios.Debug(gBuff);
    sprintf_P(gBuff,pmBIOSProxy5,&bios.temp(),PORTB, 0);
    bios.Debug(gBuff);
    bios.Debug(pmBIOSProxy6, true);

    sprintf_P(gBuff,pmBIOSProxy7,&bios.rtc(),PORTB, 0);
    bios.Debug(gBuff);
    MTime::TimeStamp(gBuff);
    bios.Debug(gBuff);

    sprintf_P(gBuff,pmBIOSProxy8, PORTA);
    bios.Debug(gBuff);
    sprintf_P(gBuff,pmBIOSProxy9,0,0);
    bios.Debug(gBuff);
    bios.Debug(pmBIOSProxy10,true);
    bios.Debug(pmBIOSProxy11,true);
    bios.Debug(pmBIOSProxy12,true);
    bios.Debug(pmPOST3,true);

    sprintf_P(gBuff,pmBIOSProxy8, PORTB);
    bios.Debug(gBuff);
    bios.Debug(pmBIOSProxy13,true);

    sprintf_P(gBuff,pmBIOSProxy8, PORTD);
    bios.Debug(gBuff);
    bios.Debug(pmBIOSProxy14,true);


    // Looking for keyboard/mouse
    bios.Debug(pmPOST0e,true);
    bios.Debug(pmPOST0f,true);
    bios.Debug(pmMenuOpt,true);
//    _delay_ms(600);
//    bios.Debug(".");
//    _delay_ms(600);
//    bios.Debug(".");
//    _delay_ms(600);
//    bios.Debug(".");
//    _delay_ms(600);
    bios.Debug(".\r\n");




}
